import request from '@/utils/request'
import { HTTP_METHOD } from '@/utils/http'

const BASE_URL = '/user'

/**
 * @export 账号密码登录
 * @param {*} email
 * @param {*} password
 * @return {*}
 */
export function login (data) {
  return request({
    url: `${BASE_URL}/admin_user_login/pwd`,
    method: HTTP_METHOD.POST,
    data,
  })
}

// 注册人员相关接口

/**
 * @export 获取注册人员列表
 * @param {*} per_page
 * @param {*} page
 * @return {*}
 */
export function getRegisterUsers (per_page, page, params) {
  return request({
    url: `${BASE_URL}/admin_user_list`,
    method: HTTP_METHOD.GET,
    params: {
      per_page,
      page,
      ...params,
    },
  })
}

/**
 * @export 获取注册人员信息
 * @param {*} per_page
 * @param {*} page
 * @return {*}
 */
 export function getRegisterUserInfo (uid) {
  return request({
    url: `${BASE_URL}/admin_user_detail/${uid}`,
    method: HTTP_METHOD.GET,
  })
}

// =======================================================================
// 后台人员相关接口

/**
 * @export 获取当前登录用户信息
 * @return {*}
 */
export function getCurrentUser () {
  return request({
    url: `${BASE_URL}/admin_detail`,
    method: HTTP_METHOD.GET,
  })
}

/**
 * @export 修改当前登录用户信息
 * @return {*}
 */
 export function modifyCurrentUser (data) {
  return request({
    url: `${BASE_URL}/admin_detail`,
    method: HTTP_METHOD.PUT,
    data,
  })
}

/**
 * @export 修改当前登录用户密码
 * @return {*}
 */
 export function modifyCurrentUserPWD (data) {
  return request({
    url: `${BASE_URL}/dmin_change_password`,
    method: HTTP_METHOD.POST,
    data,
  })
}

/**
 * @export 校验登录手机验证码
 * @param {*} email
 * @param {*} mobile
 * @param {*} code
 * @return {*}
 */
export function loginMobileVerifyCode (data) {
  return request({
    url: `${BASE_URL}/admin_user_verify_code`,
    method: HTTP_METHOD.POST,
    data,
  })
}

/**
 * @export 获取用户列表
 * @param {*} per_page 数据量
 * @param {*} page 页码
 * @param {*} did 部门id
 */
// export function getUsers(per_page, page, did) {
//   return request({
//     url: BASE_URL,
//     method: HTTP_METHOD.GET,
//     params: {
//       per_page,
//       page,
//       did
//     }
//   });
// }

/**
 * @export 获取用户信息
 * @param {*} uid 用户id
 * @return {*}
 */
export function getUser (uid) {
  return request({
    url: `${BASE_URL}/${uid}`,
    method: HTTP_METHOD.GET,
  })
}

/**
 * @export 获取用户权限
 * @param {*} uid 用户id
 * @return {*}
 */
export function getUserAuth (uid) {
  return request({
    url: `${BASE_URL}/auth/${uid}`,
    methods: HTTP_METHOD.GET,
  })
}

/**
 * @export 获取后台人员列表
 * @param {*} per_page
 * @param {*} page
 * @return {*}
 */
 export function getUsers (per_page, page, params) {
  return request({
    url: `${BASE_URL}/background_user_list`,
    method: HTTP_METHOD.GET,
    params: {
      per_page,
      page,
      ...params,
    },
  })
}

/**
 * @export 批量删除后台用户
 * @param {*} uid 用户id
 * @return {*}
 */
export function deleteUsers (uid) {
  return request({
    url: `${BASE_URL}/background_user_list`,
    method: HTTP_METHOD.DELETE,
    data: {
      uid,
    },
  })
}

/**
 * @export 重置用户密码
 * @param {*} uid 用户id
 * @return {*}
 */
export function resetUserPWD (uid) {
  return request({
    url: `${BASE_URL}/reset/pwd/${uid}`,
    method: HTTP_METHOD.PUT,
  })
}

/**
 * @export 新增后台用户
 * @param {*} data
 * @return {*}
 */
export function userAdd (data) {
  return request({
    url: `${BASE_URL}/background_user_list`,
    method: HTTP_METHOD.POST,
    data,
  })
}

/**
 * @export 用户信息修改
 * @param {*} data
 * @return {*}
 */
export function userModify (data) {
  return request({
    url: `${BASE_URL}/background_user_list`,
    method: HTTP_METHOD.PUT,
    data,
  })
}

/**
 * @export 更改用户状态active
 * @param {*} uid
 */
export function changeActive (uid) {
  return request({
    url: `${BASE_URL}/active/${uid}`,
    method: HTTP_METHOD.PUT,
  })
}
